﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using SCCN.BLL;
using SCCN.DAL;
using SCCN.Utility;

/// <summary>
///CreateIndex 的摘要说明
/// </summary>
public class CreateIndex : CreatePage
{
    CategoryBLL bllCategory = CategoryBLL.getInstance();
    public CreateIndex()
    {

    }

    /// <summary>
    /// 生成
    /// </summary>
    /// <returns></returns>
    public static bool Create()
    {
        string path = ReaderTemplate("~/template/index.html");
        string content = Fun_Rapalce_Tag(path);
        try
        {
            CreateHTMLHelper.CreateFile(HttpContext.Current.Server.MapPath("~/index.shtml"), CreatePage.encode, content);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return true;
    }

    /// <summary>
    /// 替换页面标签
    /// </summary>
    /// <param name="content"></param>
    /// <returns></returns>
    public static string Fun_Rapalce_Tag(string content)
    {
        //标签存放字典
        Dictionary<string, string> dict = new Dictionary<string, string>();
        dict.Add("{$Index_Banner1$}", Index_Banner1());//首页轮播图横
        dict.Add("{$Index_Banner2$}", Index_Banner2());//首页轮播图纵
        dict.Add("{$Index_RecentNews$}", Index_RecentNews());//最新资讯
        dict.Add("{$Index_FashionSpecial$}", Index_FashionSpecial());//潮流专栏
        dict.Add("{$Index_ChaoLiuSuBao$}", Index_ChaoLiuSuBao());//潮流速报
        dict.Add("{$Index_Video$}", Index_Video());//潮流视角
        dict.Add("{$Index_TodayStyle$}", Index_TodayStyle());//今日造型
        dict.Add("{$Index_NewsFucus$}", Index_NewsFucus());//新闻聚焦
        dict.Add("{$Index_Coolgril$}", Index_Coolgril());//coolgirl
        dict.Add("{$Index_Tmall$}", Index_Tmall());//天猫 
        content = CreateHTMLHelper.ReplaceTag(dict, content);
        return content;
    }

    public static string Index_Banner1()
    {
        StringBuilder str = new StringBuilder();
        AdSpaceBLL bllAdSpace = AdSpaceBLL.getInstance();
        AdvertisementBLL bllAdver = AdvertisementBLL.getInstance();

        SC_AdSpace obj = bllAdSpace.GetAdSpaceByName("首页轮播图");
        List<SC_Advertisement> list = bllAdver.GetAdvertisementByAdSpaceId(obj.Id);
        str.Append("<div class=\"slide_box\">");
        str.Append("<div class=\"slide_scroller\">");
        foreach (SC_Advertisement var in list)
        {
            str.Append("<a href=\"" + var.TargetUrl + "\"><img src=\"" + var.PicSrc + "\" alt=\"\" /></a>");
        }
        str.Append("</div></div>");
        return str.ToString();
    }

    /// <summary>
    /// 资讯头部banner
    /// </summary>
    /// <returns></returns>
    public static string Index_Banner2()
    {
        AdSpaceBLL bllAdSpace = AdSpaceBLL.getInstance();
        AdvertisementBLL bllAdvertisement = AdvertisementBLL.getInstance();
        SC_AdSpace objAdSpace = bllAdSpace.GetAdSpaceByName("SoCooL杂志");
        List<SC_Advertisement> list = bllAdvertisement.GetAdvertisementByAdSpaceId(objAdSpace.Id);
        StringBuilder str = new StringBuilder();
        str.Append("<ul class=\"slide_nav\">");
        int i = 1;
        foreach (SC_Advertisement var in list)
        {
            if (i == 1)
            {
                str.Append("<li><a href=\"" + var.TargetUrl + "\" class=\"current\">0" + i + "</a></li>");
            }
            else
            {
                str.Append("<li><a href=\"" + var.TargetUrl + "\">0" + i + "</a></li>");
            }
            i++;
        }
        str.Append("</ul><div class=\"slide_box\">");
        i = 0;
        foreach (SC_Advertisement var in list)
        {
            str.Append("<a href=\"#\"><img src=\"" + var.PicSrc + "\" alt=\"\" /></a>");
        }
        str.Append("</div>");
        return str.ToString();
    }

    /// <summary>
    /// 当期看点
    /// </summary>
    /// <returns></returns>
    private static string Index_RecentNews()
    {
        StringBuilder str = new StringBuilder();
        ArticleBLL bllArticle = ArticleBLL.getInstance();
        CategoryBLL bllCategory = CategoryBLL.getInstance();
        SC_Category obj = bllCategory.GetCategoryByName("当期看点");
        obj.IsDelete = false;
        List<SC_Article> list = bllArticle.GetArticleByCategoryId(obj.Id);
        int i = 0;
        str.Append("<div class=\"bt\">");
        str.Append("<div class=\"bt-name bt-zx\">");
        str.Append("</div>");
        str.Append("<a href=\"/list.aspx?categoryid=" + obj.Id + "\" target=\"_blank\" class=\"bt-more\"></a>");
        str.Append("</div>");
        str.Append("<ul class=\"order\">");
        foreach (SC_Article var in list)
        {
            if (i < 5)
            {
                str.Append("<li><a href=\"" + var.CreateUrl + "\">" + var.ArticleTitle + "</a><br>");
                str.Append("<span>POST TLME: " + Convert.ToDateTime(var.CreateDate).ToString("yyyy-MM-dd") + " by victoria_chen</span></li>");
            }
            i++;
        }
        str.Append("</ul>");
        return str.ToString();
    }

    /// <summary>
    /// 潮流专栏
    /// </summary>
    /// <returns></returns>
    private static string Index_FashionSpecial()
    {
        StringBuilder str = new StringBuilder();
        ArticleBLL bllArticle = ArticleBLL.getInstance();
        CategoryBLL bllCategory = CategoryBLL.getInstance();
        SC_Category obj = bllCategory.GetCategoryByName("潮流专栏");
        obj.IsDelete = false;   
        List<SC_Article> list = bllArticle.GetArticleByCategoryId(obj.Id);
        int i = 0;
        str.Append("<div class=\"bt\">");
        str.Append("<div class=\"bt-name bt-hot\">");
        str.Append("</div>");
        str.Append("<a href=\"/list.aspx?categoryid=" + obj.Id + "\" class=\"bt-more\"></a>");
        str.Append("</div>");
        str.Append("<ul class=\"order\">");
        foreach (SC_Article var in list)
        {
            if (i < 5)
            {
                str.Append("<li><a href=\"" + var.CreateUrl + "\">" + var.ArticleTitle + "</a><br>");
                str.Append("<span>POST TLME: " + Convert.ToDateTime(var.CreateDate).ToString("yyyy-MM-dd") + " by victoria_chen</span></li>");
            }
            i++;
        }
        str.Append("</ul>");
        return str.ToString();
    }

    /// <summary>
    /// 潮流速报
    /// </summary>
    /// <returns></returns>
    private static string Index_ChaoLiuSuBao()
    {
        StringBuilder str = new StringBuilder();
        ArticleBLL bllArticle = ArticleBLL.getInstance();
        CategoryBLL bllCategory = CategoryBLL.getInstance();
        SC_Category obj = bllCategory.GetCategoryByName("潮流速报");
        List<SC_Article> list = bllArticle.GetArticleByCategoryId(obj.Id);
        int i = 0;
        str.Append("<div class=\"bt\">");
        str.Append("<div class=\"bt-name bt-zz\">");
        str.Append("</div>");
        str.Append("<a href=\"/list.aspx?categoryid=" + obj.Id + "\" class=\"bt-more\"></a>");
        str.Append("</div>");
        str.Append("<div class=\"zz-nav\">");
        str.Append("</div>");
        str.Append("<div class=\"zz-list w110p\">");
        str.Append("<ul class=\"ll\">");
        foreach (SC_Article var in list)
        {
            if (i < 6)
            {
                str.Append("<li>");
                str.Append("<div>");
                str.Append("<a target=\"_blank\" href=\"" + var.CreateUrl + "\">");
                str.Append("<img src=\"" + var.PicCoverUrl1 + "\" alt=\"\" /></a><br />");
                str.Append("<p><a href=\"" + var.CreateUrl + "\">" + var.ArticleTitle + "</a></p>");
                str.Append("<p class=\"c-gray\">");
                str.Append("POST TIME: " + var.CreateDate + "</p>");
                str.Append("<p class=\"rel c-gray\">");
                str.Append("人气: <span class=\"c-ori\">200</span> 次 <a href=\"" + var.CreateUrl + "\" class=\"view-p\"></a></p></div></li>");
            }
            i++;
        }
        str.Append("</ul></div>");
        return str.ToString();
    }

    /// <summary>
    /// 潮流视角
    /// </summary>
    /// <returns></returns>
    private static string Index_Video()
    {
        StringBuilder str = new StringBuilder();
        ArticleBLL bllArticle = ArticleBLL.getInstance();
        CategoryBLL bllCategory = CategoryBLL.getInstance();
        SC_Category obj = bllCategory.GetCategoryByName("潮流视角");
        List<SC_Article> list = bllArticle.GetArticleByCategoryId(obj.Id);
        int i = 0;
        str.Append("<div class=\"bt\">");
        str.Append("<div class=\"bt-name bt-vd ml0\">");
        str.Append("</div>");
        str.Append("<a href=\"/list.aspx?categoryid=" + obj.Id + "\" class=\"bt-more\"></a>");
        str.Append("</div>");

        foreach (SC_Article var in list)
        {
            if (i == 0)
            {
                str.Append("<div class=\"vd-box\">");
                str.Append("<a href=\"" + var.CreateUrl + "\">");
                str.Append("<img src=\"" + var.PicCoverUrl4 + "\" alt=\"\" /></a>");
		str.Append("<span style=\"position: relative; top: 10px;\">");
		str.Append(var.ArticleTitle +"</span>");
                str.Append("<div class=\"vd-mask\">");
                str.Append("</div>");
                str.Append("</div>");
            }
            i++;
        }
        return str.ToString();
    }

    /// <summary>
    /// 今日造型
    /// </summary>
    /// <returns></returns>
    private static string Index_TodayStyle()
    {
        StringBuilder str = new StringBuilder();
        ArticleBLL bllArticle = ArticleBLL.getInstance();
        CategoryBLL bllCategory = CategoryBLL.getInstance();
        SC_Category obj = bllCategory.GetCategoryByName("今日造型");
        List<SC_Article> list = bllArticle.GetArticleByCategoryId(obj.Id).Take(1).ToList<SC_Article>();
        str.Append("<div class=\"bt\">");
        str.Append("<div class=\"bt-name bt-st ml0\">");
        str.Append("</div>");
        str.Append("<a href=\"/list.aspx?categoryid=" + obj.Id + "\" target=\"_blank\" class=\"bt-more\"></a>");
        str.Append("</div>");
        str.Append("<div class=\"vd-box\">");

        foreach (SC_Article var in list)
        {
            str.Append("<div class=\"today-style\">");
            str.Append("<div class=\"img-clip\">");
            str.Append("<a href=\"" + var.CreateUrl + "\">");
            str.Append("<img src=\"" + var.PicCoverUrl5 + "\" alt=\"\" /></a>");
            str.Append("</div><p>" + var.ArticleTitle + "</p></div>");
        }
        str.Append("<div class=\"new-lt\">");
        str.Append("</div></div>");
        return str.ToString();
    }

    /// <summary>
    /// 星闻聚焦
    /// </summary>
    /// <returns></returns>
    private static string Index_NewsFucus()
    {
        StringBuilder str = new StringBuilder();
        ArticleBLL bllArticle = ArticleBLL.getInstance();
        CategoryBLL bllCategory = CategoryBLL.getInstance();
        SC_Category obj = bllCategory.GetCategoryByName("星闻聚焦");
        List<SC_Article> list = bllArticle.GetArticleByCategoryId(obj.Id);
        int i = 0;
        str.Append("<div class=\"bt mt10 mb10\">");
        str.Append("<div class=\"bt-name bt-tidal\">");
        str.Append("</div>");
        str.Append("<a href=\"/list.aspx?categoryid=" + obj.Id + "\" target=\"_blank\" class=\"bt-more\"></a>");
        str.Append("</div>");
        str.Append("<div class=\"tidal-list w976\">");
        str.Append("<ul class=\"ll w110p\">");
        foreach (SC_Article var in list)
        {
            if (i < 4)
            {
                str.Append("<li><div>");
                str.Append("<a href=\"" + var.CreateUrl + "\">");
                str.Append("<img src=\"" + var.PicCoverUrl3 + "\" alt=\"\" /></a><p>");
                str.Append("<a href=\"" + var.CreateUrl + "\">" + var.ArticleTitle + "</a>");
                str.Append("</p></div></li>");
            }
            i++;
        }
        str.Append(" </ul></div>");
        return str.ToString();
    }

    /// <summary>
    /// COOL女孩甄选
    /// </summary>
    /// <returns></returns>
    private static string Index_Coolgril()
    {
        StringBuilder str = new StringBuilder();
        ArticleBLL bllArticle = ArticleBLL.getInstance();
        CategoryBLL bllCategory = CategoryBLL.getInstance();
        SC_Category obj = bllCategory.GetCategoryByName("COOL女孩甄选");
        List<SC_Article> list = bllArticle.GetArticleByCategoryId(obj.Id);
        int i = 0;
        str.Append("<div class=\"bt mt10 mb10\">");
        str.Append("<div class=\"bt-name bt-cr\">");
        str.Append("</div>");
        str.Append("<a href=\"/list.aspx?categoryid=" + obj.Id + "\" target=\"_blank\" class=\"bt-more\"></a>");
        str.Append("</div>");
        str.Append(" <div class=\"cr-list w976\">");
        str.Append("<ul class=\"ll w110p\">");
        foreach (SC_Article var in list)
        {
            if (i < 4)
            {
                str.Append("<li><div>");
                str.Append("<a href=\"" + var.CreateUrl + "\">");
                str.Append("<img src=\"" + var.PicCoverUrl2 + "\" alt=\"\" /></a><p>");
                str.Append("<a href=\"" + var.CreateUrl + "\">" + var.ArticleTitle + "</a>");
                str.Append("</p></div></li>");
            }
            i++;
        }
        str.Append("</ul></div>");
        return str.ToString();
    }

    /// <summary>
    /// 淘宝商城
    /// </summary>
    /// <returns></returns>
    private static string Index_Tmall()
    {
        StringBuilder str = new StringBuilder();
        ArticleBLL bllArticle = ArticleBLL.getInstance();
        CategoryBLL bllCategory = CategoryBLL.getInstance();
        SC_Category obj = bllCategory.GetCategoryByName("淘宝商城");
        List<SC_Article> list = bllArticle.GetArticleByCategoryId(obj.Id);
        int i = 0;
        str.Append("<div class=\"bt mt10 mb10\">");
        str.Append(" <div class=\"bt-name bt-hd\">");
        str.Append("</div>");
        str.Append("<a href=\"/list.aspx?categoryid=" + obj.Id + "\" target=\"_blank\" class=\"bt-more\"></a>");
        str.Append("</div>");
        str.Append("<div class=\"cr-list w976\">");
        str.Append("<ul class=\"ll w110p\">");
        foreach (SC_Article var in list)
        {
            if (i < 4)
            {
                str.Append("<li><div>");
                str.Append("<a href=\"" + var.CreateUrl + "\">");
                str.Append("<img src=\"" + var.PicCoverUrl2 + "\" alt=\"\" /></a><p>");
                str.Append("<a href=\"" + var.CreateUrl + "\">" + var.ArticleTitle + "</a>");
                str.Append("</p></div></li>");
            }
            i++;
        }
        str.Append("</ul></div>");
        return str.ToString();
    }




}